package com.myhome.money.sentinel.dubbo;

import com.alibaba.csp.sentinel.init.InitExecutor;
import com.alibaba.csp.sentinel.slots.block.RuleConstant;
import com.alibaba.csp.sentinel.slots.block.flow.FlowRule;
import com.alibaba.csp.sentinel.slots.block.flow.FlowRuleManager;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import java.util.Collections;

/**
 * @Author: 许路路
 * @Date: 2019/8/12
 */
public class DubboProviderMain {

    private static final String RES_KEY = "com.myhome.money.sentinel.dubbo.HelloService:sayHello(java.lang.String)";

    public static void main(String[] args) {

        InitExecutor.doInit();

        initFlowRule();

        AnnotationConfigApplicationContext providerContext = new AnnotationConfigApplicationContext();
        providerContext.register(ProviderConfig.class);
        providerContext.refresh();

        System.out.println("dubbo provider start...");
    }

    private static void initFlowRule() {
        FlowRule flowRule = new FlowRule();
        flowRule.setResource(RES_KEY);
        flowRule.setCount(10);
        flowRule.setGrade(RuleConstant.FLOW_GRADE_QPS);
        flowRule.setLimitApp("default");
        FlowRuleManager.loadRules(Collections.singletonList(flowRule));
    }

}
